﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SalePartial.Utility;
using SalePartial.Model;
using System.Web.Security;
using Telerik.Web.UI;
using SalePartial.BLL;
using System.Text;
using System.Data.SqlClient;
using XunPan.Web.Globals;

public partial class Login_regConfirm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Master.FinshOneProcess(REG_PROCESS.INFO_CONFIRM, REG_STATUS.USED);

            InitPersonRegInfo();
            InitPurchaseRegInfo();
            InitSupplyRegInfo();
        }
    }

    RegUserInfo userinfo = null;
    private void InitPersonRegInfo()
    {
       
        XPUserProfileInfo profileInfo = null;
        if (Session[ConstantSession.REG_PERPON_USER_INFO] == null)
        {
            MembershipUser user = Membership.GetUser(User.Identity.Name);

            if (user != null)
            {
                userinfo = new RegUserInfo();
                userinfo.Email = user.Email;
                userinfo.IsApproved = user.IsApproved;
                userinfo.PasswordQuestion = user.PasswordQuestion;
                userinfo.ProviderUserKey = user.ProviderUserKey;
                userinfo.Username = user.UserName;
            }
            else
            {
                return;
            }

        }
        else
        {
            userinfo = (RegUserInfo)Session[ConstantSession.REG_PERPON_USER_INFO];
        }

        if (Session[ConstantSession.REG_PERPON_USER_PROFILE] == null
            && userinfo != null && userinfo.ProviderUserKey!=null)
        {
            XPUserProfile xPUPF = new XPUserProfile();
            profileInfo = xPUPF.SelectInfoByUserID(new Guid(userinfo.ProviderUserKey.ToString()));

        }
        else
        {
             profileInfo = (XPUserProfileInfo)Session[ConstantSession.REG_PERPON_USER_PROFILE];
        }



        if (userinfo != null)
        {
            lblUserName.Text = userinfo.Email;
            lblPassword.Text = userinfo.Password;
            lblSecQuest.Text = userinfo.PasswordQuestion;
            lblSecAnswer.Text = userinfo.PasswordAnswer;
        }

        if (profileInfo != null)
        {
            lblJobTitle.Text = profileInfo.JobTitle;
            lblFamliyName.Text = profileInfo.FamilyName;
            lblGiveName.Text = profileInfo.FirstName;
            lblOfficePhone.Text = profileInfo.OfficePhone;
            lblCellPhone.Text = profileInfo.CellPhone;
            lblPostCode.Text = profileInfo.PostCode;
            lblCountry.Text = profileInfo.Country;
            lblPrivence.Text = profileInfo.Province;
            lblCity.Text = profileInfo.City;
            lblCadSw.Text = profileInfo.Software;
            lblReceMsg.Text = profileInfo.NotificationCollection;
        }

    }

    private void InitPurchaseRegInfo()
    {

        XPCompanyInfo companyInfo= (XPCompanyInfo) Session[ConstantSession.REG_PURCH_COMPY_INFO];
        XPCompanyCertInfo certInfo = (XPCompanyCertInfo)Session[ConstantSession.REG_PURCH_COMPYCERT_INFO];
        List<XPCompanyCertInfo> certItems = (List<XPCompanyCertInfo>)Session[ConstantSession.REG_PURCH_COMPYCERT_LIST];
        if ((companyInfo == null || certInfo == null) && userinfo != null && userinfo.ProviderUserKey!=null)
        {
            XPCompany bilCompany = new XPCompany();
            XPCompanyCert bilCorpcert = new XPCompanyCert();

            List<XPCompanyInfo> companyInfoList = bilCompany.SelectInfoByUserID(new Guid(userinfo.ProviderUserKey.ToString()));
            for(int i=0;i<companyInfoList.Count;i++)
            {
                if (companyInfoList[i].IsApproved)
                {
                    companyInfo = companyInfoList[i];

                    List<XPCompanyCertInfo> companycertList = bilCorpcert.SelectInfoByCompanyID(companyInfo.CompanyID);
                    certItems = new List<XPCompanyCertInfo>();
                    for(int j=0;j<companycertList.Count;j++)
                    {
                        
                        if (companycertList[j].CertType == 1)
                        {
                            certInfo = companycertList[j];
                        }
                        else
                        {
                            certItems.Add( companycertList[j]);
                        }
                    }
                    break;
                }
            }

            
        }

        if (companyInfo == null || certInfo == null)
        {
            panelPurch.Visible = false;
            lkUpdPurch.Visible = false;
            panelPurchNothing.Visible = true;
            return;
        }

        panelPurch.Visible = true;
        lkUpdPurch.Visible = true;
        panelPurchNothing.Visible = false;
        
        lblCompanyNameP.Text = companyInfo.CompanyName;
        lblIndustryP.Text = companyInfo.Industry;
        lblWebsiteP.Text = companyInfo.WebSite;
        lblFundP.Text = companyInfo.Fund;
        //职位=CompanyOwner?????
        lblJobtitleP.Text = companyInfo.CompanyOwner;
        lblPhoneP.Text = companyInfo.OfficePhone;
        cbPhoneP.Checked = companyInfo.IsCellPhonePublic;
        lblCellphoneP.Text = companyInfo.CellPhone;
        cbCellphoneP.Checked = companyInfo.IsCellPhonePublic;
        lblFaxP.Text = companyInfo.Fax;
        lblFirmSizeP.Text = companyInfo.Scale;
        imgPhoto.ImageUrl = companyInfo.Photo;
        imgLogo.ImageUrl = companyInfo.Logo;
        lblMoney.Text = companyInfo.Monetary;
        lblCmpyDesc.Text = companyInfo.Description;



        lblComyNo.Text = certInfo.CertName;

        if (certInfo.CertFileData != null)
        {
            lblCmpyImg.ImageUrl = Encoding.Unicode.GetString(certInfo.CertFileData);
        }

        rptUploadedCerts.DataSource = certItems;
        rptUploadedCerts.DataBind();
        rptUploadedCerts.Visible = true;
    }

    private void InitSupplyRegInfo()
    {

        XPCompanyInfo companyInfo = (XPCompanyInfo)Session[ConstantSession.REG_SUPPLY_COMPY_INFO];
        XPCompanyCertInfo certInfo = (XPCompanyCertInfo)Session[ConstantSession.REG_SUPPLY_COMPYCERT_INFO];

        List<XPCompanyCertInfo> certItems = (List<XPCompanyCertInfo>)Session[ConstantSession.REG_SUPPLY_COMPYCERT_LIST];
        List<XPCompanyProductInfo> productItems = (List<XPCompanyProductInfo>)Session[ConstantSession.REG_SUPPLY_COMPYPRDCT_LIST];

        if ((companyInfo == null || certInfo == null) && userinfo != null && userinfo.ProviderUserKey != null)
        {
            XPCompany bilCompany = new XPCompany();
            XPCompanyCert bilCorpcert = new XPCompanyCert();

            List<XPCompanyInfo> companyInfoList = bilCompany.SelectInfoByUserID(new Guid(userinfo.ProviderUserKey.ToString()));
            for (int i = 0; i < companyInfoList.Count; i++)
            {
                if (!companyInfoList[i].IsApproved)
                {
                    companyInfo = companyInfoList[i];

                    List<XPCompanyCertInfo> companycertList = bilCorpcert.SelectInfoByCompanyID(companyInfo.CompanyID);
                    certItems = new List<XPCompanyCertInfo>();
                    for (int j = 0; j < companycertList.Count; j++)
                    {
                        if (companycertList[j].CertType == 1)
                        {
                            certInfo = companycertList[j];
                        }
                        else
                        {
                            certItems.Add(companycertList[j]);
                        }
                    }
                    break;
                }
            }


        }

        if (companyInfo == null || certInfo == null)
        {
            panelSupply.Visible = false;
            lkUpdSupply.Visible = false;
            panelSupplyNothing.Visible = true;
            return;
        }

        panelSupply.Visible = true;
        lkUpdSupply.Visible = true;
        panelSupplyNothing.Visible = false;


        lblCompanyName.Text = companyInfo.CompanyName;
        lblIndustry.Text = companyInfo.Industry;
        lblWebsite.Text = companyInfo.WebSite;
        lblFund.Text = companyInfo.Fund;
        //职位=CompanyOwner?????
        lblJobtitleS.Text = companyInfo.CompanyOwner;
        lblPhoneS.Text = companyInfo.OfficePhone;
        cbPhone.Checked = companyInfo.IsCellPhonePublic;
        lblCellphoneS.Text = companyInfo.CellPhone;
        cbCellphone.Checked = companyInfo.IsCellPhonePublic;
        lblFaxS.Text = companyInfo.Fax;
        cbFax.Checked = companyInfo.IsFaxPublic;
        lblCurrencyS.Text = companyInfo.Monetary;
        lblFirmSize.Text = companyInfo.Scale;
        lblDescriptionS.Text = companyInfo.Description;
        imgPhotoS.ImageUrl = companyInfo.Photo;
        imgLogoS.ImageUrl = companyInfo.Logo;

        lblLicenseS.Text = certInfo.CertName;
        if (certInfo.CertFileData != null)
        {
            imgLicense.ImageUrl = Encoding.Unicode.GetString(certInfo.CertFileData);
        }

        lblCategoryTree.Text = companyInfo.Product;
        lblProcessTree.Text = companyInfo.Technology;

        rgridCompanyCerts.DataSource = certItems;
        rgridCompanyCerts.DataBind();
        rgridCompanyCerts.Visible = true;

        rgridCompanyProducts.DataSource = productItems;
        rgridCompanyProducts.DataBind();
        rgridCompanyProducts.Visible = true;


    }


    protected void ibtSubmit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {

        if (!submitPersonInfo())
        {
            return;
        }

        if (!submitPurchaseInfo())
        {
            return;
        }

        if (!submitSupplyInfo())
        {
            return;
        }

        Session.Remove(ConstantSession.REG_PERPON_USER_INFO);
        Session.Remove(ConstantSession.REG_PERPON_USER_PROFILE);
        
        Session.Remove(ConstantSession.REG_PURCH_COMPY_INFO);
        Session.Remove(ConstantSession.REG_PURCH_COMPYCERT_INFO);
        Session.Remove(ConstantSession.REG_PURCH_COMPYCERT_LIST);

        Session.Remove(ConstantSession.REG_SUPPLY_COMPY_INFO);
        Session.Remove(ConstantSession.REG_SUPPLY_COMPYCERT_INFO);
        Session.Remove(ConstantSession.REG_SUPPLY_COMPYCERT_LIST);
        Session.Remove(ConstantSession.REG_SUPPLY_COMPYPRDCT_LIST);

        RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('恭喜您，注册成功！！！')", true);
        Page.Response.Redirect("~/Login/regSuccess.aspx", true);
        
    }

    protected void ibtBack_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        Master.GoBackPreProcess();
        string prePage = (string)Session[ConstantSession.PRE_PAGE_ID];
        if (prePage != null)
        {
            Page.Response.Redirect(prePage, true);
        }
        else
        {
            Page.Response.Redirect("~/Login/regPerson.aspx", true);
        }
    }

    private bool submitPersonInfo()
    {
        if (Session[ConstantSession.REG_PERPON_USER_INFO] == null)
        {
            return true;
        }

        if (Session[ConstantSession.REG_PERPON_USER_PROFILE] == null)
        {
            return true;
        }

        RegUserInfo userinfo = (RegUserInfo)Session[ConstantSession.REG_PERPON_USER_INFO];
        XPUserProfileInfo profileInfo = (XPUserProfileInfo)Session[ConstantSession.REG_PERPON_USER_PROFILE];


        
        //声明一个 MembershipCreateStatus 
        //以保存在新建用户过程中新建的状态 
        MembershipCreateStatus createUserStatus = default(MembershipCreateStatus);
        //XunPanMembershipProvider  shipProvider = new XunPanMembershipProvider();
        //调用 Membership.CreateUser() 来新建 
        //并且把 MembershipCreateStatus 对象传递给了这个方法 
        MembershipUser newRegUser = default(MembershipUser);

        XPUserProfile xPUPF = new XPUserProfile();
        bool blRt = false;
        if(userinfo.ProviderUserKey != null)
        {
            Guid newUserID = new Guid(userinfo.ProviderUserKey.ToString());
            profileInfo.UserID = newUserID;

            try
            {
                xPUPF.Update(profileInfo);
                blRt = true;
            }
            catch (Exception ex)
            {
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('信息注册失败！')", true);
                return false;

            }
        }
            else{
        newRegUser = Membership.CreateUser(userinfo.Username, userinfo.Password,
            userinfo.Username, userinfo.PasswordQuestion, userinfo.PasswordAnswer, userinfo.IsApproved, out createUserStatus);
            

       
        
        //取得新建过程中的状态值的字符串表示 
        //可以使用 MembershipCreateStatus .  这种方式来得到智能提示 
        //从而得到所有的结果字符串如下所有的 case 中  
        switch (createUserStatus.ToString())
        {
            case "DuplicateEmail":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('您注册的邮箱已经存在了！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "DuplicateProviderUserKey":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('您注册的邮箱已经存在了！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "DuplicateUserName":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('您注册的用户名已经存在了！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidAnswer":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('密码恢复问题解答验证失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidEmail":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('邮箱验证失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidPassword":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('密码验证失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidProviderUserKey":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('无效的提供程序用户索引！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidQuestion":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('密码恢复问题验证失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "InvalidUserName":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('用户名验证失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "ProviderError":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('提供程序返回错误！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            case "Success":



                //If newRegUser Is Nothing Then
                //    newRegUser = Membership.GetUser(tbUsername.Text.Trim())
                //End If

                Guid newUserID = new Guid(newRegUser.ProviderUserKey.ToString());
                profileInfo.UserID = newUserID;

                try
                {
                    xPUPF.Insert(profileInfo);
                    blRt = true;
                }
                catch (Exception ex)
                {
                    Membership.DeleteUser(newRegUser.UserName, true);
                    RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('信息注册失败！')", true);
                    return false;

                }

                Roles.AddUserToRole(userinfo.Username, "individual");
                //将用户加入Individual角色  

              

                break; // TODO: might not be correct. Was : Exit Select

            case "UserRejected":
                RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "alert('提供程序定义问题造成创建失败！！！')", true);
                break; // TODO: might not be correct. Was : Exit Select

            default:
                break; // TODO: might not be correct. Was : Exit Select

        }
            }
        return blRt;
    }

    private bool submitPurchaseInfo()
    {
        XPCompanyInfo companyInfo = (XPCompanyInfo)Session[ConstantSession.REG_PURCH_COMPY_INFO];
        XPCompanyCertInfo certInfo = (XPCompanyCertInfo)Session[ConstantSession.REG_PURCH_COMPYCERT_INFO];
        List<XPCompanyCertInfo> certItems = (List<XPCompanyCertInfo>)Session[ConstantSession.REG_PURCH_COMPYCERT_LIST];
        if (companyInfo == null || certInfo == null)
        {
            return true;
        }
        bool blIsNew = false;
        int  blResult = 0;
        XPCompany bilCompany = new XPCompany();
        XPCompanyCert bilCorpcert = new XPCompanyCert();

        MembershipUser reguser = Membership.GetUser(lblUserName.Text);
       
        if (reguser != null)
        {
            Guid userid = new Guid(reguser.ProviderUserKey.ToString());

            if (companyInfo.CompanyID == Guid.Empty || companyInfo.UserID == Guid.Empty)
            {
                companyInfo.UserID = userid;
                //为了区分 purchase和supply两个用户，暂时用这个字段区分
                companyInfo.IsApproved = true;
                //companyInfo.LicenseCertID = new Guid(ConstantSession.REG_PURCH_COMPYCERT_INFO);
                blResult = bilCompany.Insert(companyInfo);
                blIsNew = true;
            }
            else
            {
                blResult = bilCompany.Update(companyInfo);
            }


            SqlDataReader reader = bilCompany.SelectReaderByUserID(userid);

            while (reader.Read())
            {
                XPCompanyInfo company = new XPCompanyInfo(reader);
                if (company.IsApproved == false)
                {
                    continue;
                }

                certInfo.CertType = 1;
                if (certInfo.CompanyID == Guid.Empty || certInfo.CreateUserID == Guid.Empty)
                {
                    certInfo.CompanyID = company.CompanyID;
                    certInfo.CreateUserID = company.UserID;
                    bilCorpcert.Insert(certInfo);
                }
                else
                {
                    bilCorpcert.Update(certInfo);
                }

                if (certItems != null)
                {
                    XPCompanyCertInfo cert = default(XPCompanyCertInfo);
                    for (int i = 0; i < certItems.Count ; i++)
                    {
                        cert = new XPCompanyCertInfo();

                        var _with5 = cert;
                        _with5.CertType = 2;
                    


                        _with5.CertName = certItems[i].CertName;
                        _with5.CertFileName = certItems[i].CertFileName;
                        _with5.CertFileSize = certItems[i].CertFileSize;
                        _with5.CertFileContentType = certItems[i].CertFileContentType;
                        //if (System.IO.File.Exists(Encoding.Unicode.GetString(certItems[i].CertFileData)))
                        //{
                            _with5.CertFileData = certItems[i].CertFileData;
                            //_with5.CertFileData = System.IO.File.ReadAllBytes(Server.MapPath(certItems[i].FilePath));
                        //}
                            if (certItems[i].CompanyID == Guid.Empty || certItems[i].CreateUserID == Guid.Empty)
                            {
                                _with5.CompanyID = company.CompanyID;
                                _with5.CreateUserID = company.UserID;
                                bilCorpcert.Insert(_with5);
                            }
                            else
                            {
                                bilCorpcert.Update(_with5);
                            }

                        //System.IO.File.Delete(Server.MapPath(certItems[i].FilePath));
                    }

                    Session.Remove("s_list_uploadedcerts");
                }

                if (blIsNew)
                {
                    Roles.AddUserToRole(reguser.UserName, "purchase");
                }
            }
            //else {
				//personal user
				if (!reader.IsClosed) 
                {
					reader.Close();
				}
            //}

        }


        return true;
    }

    private bool submitSupplyInfo()
    {
        XPCompanyInfo companyInfo = (XPCompanyInfo)Session[ConstantSession.REG_SUPPLY_COMPY_INFO];
        XPCompanyCertInfo certInfo = (XPCompanyCertInfo)Session[ConstantSession.REG_SUPPLY_COMPYCERT_INFO];
        List<XPCompanyCertInfo> certInfoLists = (List<XPCompanyCertInfo>)Session[ConstantSession.REG_SUPPLY_COMPYCERT_LIST];
        List<XPCompanyProductInfo> productInfoLists = (List<XPCompanyProductInfo>)Session[ConstantSession.REG_SUPPLY_COMPYPRDCT_LIST];

        if (companyInfo == null || certInfo == null)
        {
            return true;
        }
        bool blIsNew = false;
        int blResult = 0;
        XPCompany bilCompany = new XPCompany();
        XPCompanyCert bilCorpcert = new XPCompanyCert();

        MembershipUser reguser = Membership.GetUser(lblUserName.Text);

        if (reguser != null)
        {
            Guid userid = new Guid(reguser.ProviderUserKey.ToString());

            if (companyInfo.CompanyID == Guid.Empty || companyInfo.UserID == Guid.Empty)
            {
                //为了区分 purchase和supply两个用户，暂时用这个字段区分
                companyInfo.IsApproved = false;
                //companyInfo.LicenseCertID = new Guid(ConstantSession.REG_SUPPLY_COMPYCERT_INFO);
                companyInfo.UserID = userid;
                blResult = bilCompany.Insert(companyInfo);
                blIsNew = true;
            }
            else
            {
                blResult = bilCompany.Update(companyInfo);
            }

            SqlDataReader reader = bilCompany.SelectReaderByUserID(userid);

            while (reader.Read())
            {
                XPCompanyInfo company = new XPCompanyInfo(reader);
                if (company.IsApproved == true)
                {
                    continue;
                }

                certInfo.CertType = 1;
                if (certInfo.CompanyID == Guid.Empty || certInfo.CreateUserID == Guid.Empty)
                {
                    certInfo.CompanyID = company.CompanyID;
                    certInfo.CreateUserID = company.UserID;
                    bilCorpcert.Insert(certInfo);
                }
                else
                {
                    bilCorpcert.Update(certInfo);
                }

                if (certInfoLists != null)
                {
                    XPCompanyCertInfo cert = default(XPCompanyCertInfo);
                    for (int i = 0; i < certInfoLists.Count; i++)
                    {
                        cert = new XPCompanyCertInfo();

                        var _with5 = cert;
                        _with5.CertType = 2;
                        


                        _with5.CertName = certInfoLists[i].CertName;
                        _with5.CertFileName = certInfoLists[i].CertFileName;
                        _with5.CertFileSize = certInfoLists[i].CertFileSize;
                        _with5.CertFileContentType = certInfoLists[i].CertFileContentType;
                        //if (System.IO.File.Exists(Server.MapPath(Encoding.Unicode.GetString( certInfoLists[i].CertFileData))))
                        //{
                            _with5.CertFileData = certInfoLists[i].CertFileData;
                            //_with5.CertFileData = System.IO.File.ReadAllBytes(Server.MapPath(certItems[i].FilePath));
                        //}
                            if (certInfoLists[i].CompanyID == Guid.Empty || certInfoLists[i].CreateUserID == Guid.Empty)
                            {
                                _with5.CompanyID = company.CompanyID;
                                _with5.CreateUserID = company.UserID;
                                bilCorpcert.Insert(_with5);
                            }
                            else
                            {
                                bilCorpcert.Update(_with5);
                            }

                        //System.IO.File.Delete(Server.MapPath(certItems[i].FilePath));
                    }

                    //Session.Remove("s_list_uploadedcerts");
                }


                if (productInfoLists != null)
                {
                    XPCompanyProduct bilXPCP = new XPCompanyProduct();

                    XPCompanyProductInfo product = default(XPCompanyProductInfo);
                    for (int i = 0; i < productInfoLists.Count; i++)
                       {
                           product = productInfoLists[i];

                           var _with5 = product;
                      
                           try
                           {
                               if (product.ProductID == Guid.Empty)
                               {
                                   _with5.ProductID = Guid.NewGuid();
                                   _with5.CompanyID = company.CompanyID;
                                   _with5.CreateUserID = company.UserID;
                                   bilXPCP.Insert(_with5);
                               }
                               else
                               {
                                   bilXPCP.Update(_with5);
                               }
                           }
                           catch (Exception ex)
                           {
                              
                           }
                       }
                }

                if (blIsNew)
                {
                    Roles.AddUserToRole(reguser.UserName, "suppliers");
                }
            }
            //else
            //{
                //personal user
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            //}

        }


        return true;
    }
    protected void lkUpdSupply_Click(object sender, EventArgs e)
    {
        Master.GoBackPreProcess();
        Page.Response.Redirect("~/Login/regSupplies.aspx", true);
    }
    protected void lkUpdPurch_Click(object sender, EventArgs e)
    {
        Master.GoBackPreProcess();
        Page.Response.Redirect("~/Login/regPurchases.aspx", true);
    }
    protected void lkUpdPerson_Click(object sender, EventArgs e)
    {
        Master.GoBackPreProcess();
        Page.Response.Redirect("~/Login/regPerson.aspx", true);
    }
}